home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5415 < prev    next >
Encoding:
Text File  |  1996-08-05  |  876 b   |  40 lines

  1. Path: wisipc.weizmann.ac.il!news
  2. Newsgroups: comp.lang.c++
  3. Subject: Heap Memory Management
  4. Message-ID: <1996Feb4.140550.4699@wisipc.weizmann.ac.il>
  5. From: Kajdan Dimitry <cerlpvk>
  6. Date: Sun, 4 Feb 1996 14:05:50 GMT
  7. Sender: news@wisipc.weizmann.ac.il (News User)
  8. Organization: Technion - Israel Institute of Technology
  9. Content-Type: text/plain; charset=us-ascii
  10. Content-Transfer-Encoding: 7bit
  11. Mime-Version: 1.0
  12. X-Mailer: Mozilla 1.1N (X11; I; OSF1 V3.2 alpha)
  13. X-Url: news://wisipc.weizmann.ac.il/comp.lang.c++
  14.  
  15. Hi.
  16. Would someone explain please.
  17.  
  18. Suppose one got a function that allocates memory on the free store.
  19.  
  20. char* func(int n)
  21. {
  22. char* a=new char[n];
  23. strcpy(a,"Hello");
  24. return a;
  25. }
  26.  
  27. int main()
  28. {
  29.  
  30. char* b=func(10);
  31.  
  32. return(0);
  33.  
  34. }
  35.  
  36. The question is how the memory allocated by new can be freed, since as soon as 
  37. func() terminates the user loses access to it.
  38. Thanks a lot
  39.  
  40.